package Servlet.Admin;

import Service.Admin.AdminCountService;
import Service.Admin.GradingManagementService;
import Service.Admin.Imp.AdminCountServiceImp;
import Service.Admin.Imp.GradingManagementServiceImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = {"/adminStuCount","/assignCount","/reportCount","/mediumCount","/firstCount","/finalizeCount","/finalCount"})
public class AdminCountServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String url = request.getRequestURI();
        if ("/adminStuCount".equals(url)) {
            adminStuCount(request, response);
        } else if ("/assignCount".equals(url)) {
            assignCount(request,response);
        } else if ("/reportCount".equals(url)) {
            reportCount(request,response);
        } else if ("/mediumCount".equals(url)) {
            mediumCount(request, response);
        } else if ("/firstCount".equals(url)) {
            firstCount(request,response);
        }else if ("/finalizeCount".equals(url)) {
            finalizeCount(request,response);
        } else if ("/finalCount".equals(url)) {
            finalCount(request,response);
        }
    }
    /**查询学生总数*/
    private void adminStuCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.adminStuCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }


    /**任务书学生数*/
    private void assignCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.assignCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }
    /**开题报告学生数*/
    private void reportCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.reportCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }
    /**中期检查学生数*/
    private void mediumCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.mediumCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }
    /**论文初稿学生数*/
    private void firstCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.firstCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }
    /**定稿学生数*/
    private void finalizeCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.finalizeCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }
    /**终稿学生数*/
    private void finalCount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AdminCountService adminCountService = new AdminCountServiceImp();
        String res = adminCountService.finalCount();
        PrintWriter out = response.getWriter();
        out.print(res);
        out.close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
